package web;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import domain.AjaxResult;
import domain.Page;
import domain.Standard;
import service.StandardService;

@Controller
@RequestMapping("/standard")
public class StandardController {
	@Autowired
	private StandardService service;
	
	@RequestMapping("/list")
	@ResponseBody
	public List<Standard> initlized() {
		System.out.println("standard list"+service.getCount());
		return service.getAll();	
	}
	@RequestMapping("/page")
	@ResponseBody
	public Page<Standard> findPage(
			@RequestParam(name = "page", defaultValue = "1") Integer page, 
			@RequestParam(name = "size", defaultValue = "10") Integer size) {
		if (page <= 0) page = 1;
		if (size <= 0) size = 10;
		
		return service.findPage(page, size);
	}
	@RequestMapping("/delete")
	@ResponseBody
	public AjaxResult delete(Standard s) {
		boolean flag=service.delete(s);
		if(flag) {
			return AjaxResult.success();
		}else {
			return AjaxResult.faile();
		}
	}
	@RequestMapping("/update")
	@ResponseBody
	public AjaxResult updtate(Standard s) {
		boolean flag=service.update(s);
		if(flag) {
			return AjaxResult.success();
		}else {
			return AjaxResult.faile();
		}		
	}
}
